<?php

namespace app\index\controller;
use app\CommonController;
use app\service\ArticleService;
use app\service\MarketService;
use app\service\ThumbService;
use app\model\Thumb;
use app\model\Market;
use app\model\Article;
class Index extends CommonController
{


    public function index()
    {
        $thumbService = $this->app->make(ThumbService::class);
        $articleService = $this->app->make(ArticleService::class);
        $markService = $this->app->make(MarketService::class);
        $thumbList = $thumbService->getAll(["status"=>Thumb::THUMB_STATUS_ACTIVE],"id,link_url,thumb");
        $marketList = $markService->getListLimitWith(
            ["status"=>Market::MARKET_STATUS_ACTIVE,'is_primary'=>1],
            "id,code,icon,open,close,vol",
            [],
            0,
            "sort asc"
        );
        foreach ($marketList as $k=>$v) {
            $low =  floatval($v["close"])- floatval($v["open"]); //涨跌
            $change = round(($low  / $v["open"] * 100),2); //涨跌幅
            $marketList[$k]["change"] = $change;
        }
        $params["status"] = Article::ARTICLE_STATUS_ACTIVE;
        $params["category_id"] = 1;
        $noticeList =  $articleService->getListLimitWith($params, "*", ["categories"]);
        $this->assign(compact("thumbList","marketList","noticeList"));
        $this->assign("customer_link",h_get_customer_url());
        return $this->fetch("index");
    }



    public function list()
    {
        $markService = $this->app->make(MarketService::class);
        $marketList = $markService->getListLimitWith(
            ["status"=>Market::MARKET_STATUS_ACTIVE],
            "id,code,icon,open,close",
            [],
            0,
            "sort asc"
        );
        foreach ($marketList as $k=>$v) {
            $low =  floatval($v["close"])- floatval($v["open"]); //涨跌
            $change = round(($low  / $v["open"] * 100),2); //涨跌幅
            $marketList[$k]["change"] = $change;
        }
        $this->assign(compact("marketList"));
        return $this->fetch("list");
    }

}
